package com.base.cn.platform.os.controller.qa;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.qa.qaattend.QaAttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 问答围观Controller接口
 *
 * @author s.li
 * @create 2018-09-06-18:39
 */
@RestController
@RequestMapping("/api/qa")
public class ApiQaAttendController extends ApiBaseController {

    @Autowired
    private QaAttendService qaAttendService;

    /**
     * 查询问答详情下的围观数据
     * @param questionId 问答ID
     * @return Map<String,Object>
     */
    @RequestMapping("/queryAttendListByQuestionId")
    public Map<String,Object> queryAttendListByQuestionId(@RequestParam("questionId")BigDecimal questionId){
        Map<String,Object> params = new HashMap<>();
        params.put("questionId",questionId);
        BigDecimal attendCount = qaAttendService.attendCount(params);
        params.put("count",10);
        List<Map<String,Object>> attendList = qaAttendService.findQaAttendList(params,true);
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("attendCount",attendCount);
        dataMap.put("attendList",attendList);
        return ResultUtil.SUCCESS(dataMap);
    }
}
